<?php

require_once __DIR__.'/token.php';

class FILTER{
    /**
     *
     * @param string $string 需要加密的字符串
     * @param string $key 密钥
     * @return string
     */
    public static function permissions_filtering($url_array, $token)
    {
        $request_file = ABSPATH .'app/'.$url_array[0].'/'.$url_array[1].'.php';
        if($url_array[0] == 'api'){
            if($url_array[1] == 'authorizations' ||
            $url_array[1] == 'registers' ||
            $url_array[1] == 'specialities' ||
            $url_array[1] == 'test_data' || $url_array[1] == 'test' ||
            $url_array[1] == 'snifferdata'){
                require_once $request_file;
            }else{
                $user = token_verify($token);
                $GLOBALS['user_id'] = $user['id'];
                $GLOBALS['user_identity'] = $user['identity'];
                if($GLOBALS['user_id'] != ''){
                    require_once $request_file;
                }else{
                    require_once ABSPATH .'app/api/401.php';
                }
            }
        }
    }
}